package com.ebook.service.implement;

import com.ebook.database.dao.BookDao;
import com.ebook.database.dao.CategoryDao;
import com.ebook.entity.Book;
import com.ebook.service.BookService;
import com.ebook.ui.fragment.bookfind.Keyword;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
@Service("bookService")
public class BookServiceImpl implements BookService {
    @Autowired
    private BookDao bookDao;
    @Autowired
    private CategoryDao categoryDao;
    @Override
    public List<Book> selectAll() {
        return bookDao.selectAll();
    }

    @Override
    public List<Book> selectBookByName(String book_name) {
        return bookDao.selectBookByName(book_name);
    }

    @Override
    public Book selectBookById(Integer book_id) {
        return bookDao.selectBookById(book_id);
    }

    @Override
    public List<Book> selectBookByIsCharge(boolean charge) {
        return bookDao.selectBookByIsCharge(charge);
    }

    @Override
    public List<Book> selectBookByCategoryId(Integer category_id) {
        return bookDao.selectBookByCategoryId(category_id);
    }

    @Override
    public List<Book> selectBookByCategoryName(String category_name) {
        return bookDao.selectBookByCategoryId(categoryDao.getCategoryIdByCategoryName(category_name));
    }

    @Override
    public String getBookAuthorByBookId(Integer book_id) {
        return bookDao.selectBookById(book_id).getAuthors();
    }

    @Override
    public ArrayList<String> getBookDirectoryByBook_id(Integer book_id) {
        Book bk = bookDao.selectBookById(book_id);
        String bkDirectory = bk.getDirectory();
        String[] bkDirectories = bkDirectory.split(",");
        return new ArrayList<>(List.of(bkDirectories));
    }

    @Override
    public ArrayList<Book> selectBookByKeyWord(Keyword keyword) {
        return null;
    }
}
